package com.tbvtc.agriculturalcreditchainserver2025.pojo;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.tbvtc.agriculturalcreditchainserver2025.Json.TimesTampSerialized;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
public class IotList {
    @Schema(description = "设备ID")
    private String deviceId;
    @Schema(description = "设备类型")
    private String deviceType;
    @Schema(description = "数据")
    private String data;
    @Schema(description = "地址")
    private String address;
    @Schema(description = "时间戳")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    @JsonSerialize(using = TimesTampSerialized.class)
    private String timestamp;
    @JsonCreator // 构造函数
    public IotList(List<Object> array) {
        this.deviceId = (String) array.get(0);
        this.deviceType = (String) array.get(1);
        this.data = (String) array.get(2);
        this.address = (String) array.get(3);
        this.timestamp=((Number) array.get(4)).toString();
//        this.timestamp = LocalDateTime.ofInstant(
//                Instant.ofEpochMilli(((Number) array.get(4)).longValue()),
//                ZoneId.of("Asia/Shanghai")
//        );
    }

}
